<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>邀请注册</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <link rel="stylesheet" href="https://api.hswlm.cn/api/static/css/style.css"/>
    <!-- 使用rem，需另外引入ydui.flexible.js自适应类库 -->
    <link rel="stylesheet" href="//unpkg.com/vue-ydui/dist/ydui.rem.css">
    <script src="https://api.hswlm.cn/api/static/js/DES3.js"></script>
    <script src="//unpkg.com/vue-ydui/dist/ydui.flexible.js"></script>

    <!-- 引入Vue2.x -->
    <script src="//vuejs.org/js/vue.min.js"></script>
    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
    <!-- 引入组件库 -->
    <script src="//unpkg.com/vue-ydui/dist/ydui.rem.js"></script>
</head>

<body>
<div class="register-top">
    <img src="https://api.hswlm.cn/api/static/img/top.png"/>
</div>
<div class="register-form" id="app">

    <yd-cell-group>
        <yd-cell-item>
            <span slot="left">手机号：</span>
            <yd-input slot="right" required v-model="formItem.accountName" max="20" placeholder="请输入手机号"></yd-input>
        </yd-cell-item>
        <yd-cell-item>
            <span slot="left">验证码：</span>
            <input type="text" slot="right" v-model="formItem.smsCode" placeholder="请输入验证码">
            <yd-sendcode slot="right" v-model="start1" @click.native="getSmsCode" type="warning"></yd-sendcode>
        </yd-cell-item>

        <yd-cell-item>
            <span slot="left">密码：</span>
            <yd-input slot="right" type="password" v-model="formItem.password" placeholder="请输入密码"></yd-input>
        </yd-cell-item>
        <yd-button size="large" type="primary" shape="circle" @click.native="onSubmit">立即注册</yd-button>
    </yd-cell-group>

</div>

<script type="text/javascript">
    new Vue({
        el: '#app',
        data: {
            formItem: {
                accountName: '',
                smsCode: '',
                inviter: '[[${shareCode}]]',
                password: '',
            },
            time: 0,
            start1: false,
            second: 60,
            disabled: false,


        },
        methods: {
            onSubmit: function () {
                if (!this.formItem.accountName) {
                    this.$dialog.toast({
                        mes: '请输入手机号',
                        timeout: 1500
                    });
                    return;
                }
                if (!this.formItem.smsCode) {
                    this.$dialog.toast({
                        mes: '请输入验证码',
                        timeout: 1500
                    });
                    return;
                }
                if (!this.formItem.password) {
                    this.$dialog.toast({
                        mes: '请输入密码',
                        timeout: 1500
                    });
                    return;
                }
                this.$http.post('/api/login/register', this.formItem, {emulateJSON: true}).then(function (res) {
                    this.$dialog.toast({
                        mes: res.body.message,
                        timeout: 1500,
                        icon: 'success'
                    });
                }, function (res) {
                });
            },
            getSmsCode() {
                if (!this.formItem.accountName) {
                    this.$dialog.toast({
                        mes: '请输入手机号',
                        timeout: 1500
                    });
                    return;
                }
                var reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
                if (!reg.test(this.formItem.accountName)) {
                    this.$dialog.toast({
                        mes: '请输入正确手机号',
                        timeout: 1500
                    });
                    return;
                }
                this.$dialog.loading.open('发送中...');
                var me = this;
                var params = {
                    mobile: encrypt(this.formItem.accountName),
                    useType: 'REG'
                }
                this.$http.post("/api/common/getSmsCode", params, {emulateJSON: true}).then(function (res) {
                    me.start1 = true;
                    me.$dialog.loading.close();
                    me.$dialog.toast({
                        mes: res.body.message,
                        timeout: 1500
                    });
                    window.location.href = '/api/common/download';
                }, function (err) {
                    me.start1 = false;
                })
            }
        },
        created: function () {

        }
    });
</script>
</body>

</html>